<?php // no direct access
defined('_JEXEC') or die('Restricted access'); ?>
<?php if ( $this->params->def( 'show_page_title', 1 ) ) : ?>
	<div class="componentheading<?php echo $this->params->get( 'pageclass_sfx' ); ?>">
		<?php echo $this->escape($this->params->get('page_title')); ?>
	</div>
<?php endif; ?>

<?php 
	$edate = JRequest::getVar( 'date',  mktime(0,0,0, date("m"), date("d"), date("Y")));
	$passed = array('year' =>0, 'month' => '', 'day' => 0);
?>
<div class="navigation">
	<div class="previous">
	<a href="<?php echo JRoute::_( 'index.php?option=com_sharing&date=' . ($edate - (60 * 60 * 24 * 7) ))?>"><?php echo JText::_( 'Previous' ) ?></a>
	</div>
	<div class="next">
	<a href="<?php echo JRoute::_( 'index.php?option=com_sharing&date=' . ($edate + (60 * 60 * 24 * 7) ))?>"><?php echo JText::_( 'Next' ) ?></a>
	</div>
</div>
<table cellpadding='0' cellspacing='0' width='100%'>
<tr>
<td class="sectiontableheader">
<?php echo JText::_( 'Year' ) ?>
</td>
<td class="sectiontableheader">
<?php echo JText::_( 'Month' ) ?>
</td>
<td class="sectiontableheader">
<?php echo JText::_( 'Date' ) ?>
</td>
<td class="sectiontableheader">
<?php echo JText::_( 'Hours and Group' ) ?>
</td>
</tr>
<?php
	$k = 0;
 	for ($i = 0; $i < 7; $i++) : ?>
<?php
				
	$date = ($edate + ($i * 86400));
	
	$year = date("Y", $date);
	$month = date("F", $date);
	$day = date("d", $date);
?>
<tr class="sectiontableentry<?php echo $k + 1; ?>">
<?php 
$k = 1 - $k;
?>
<td valign='top' width='10%' class="year">
<?php if ($passed['year'] != $year):
$passed['year'] = $year;
?>
<?php echo $year ?>
<?php endif; ?>
</td>
<td valign='top' width='10%' class="month">
<?php if ($passed['month'] != $month): 
$passed['month'] = $month;
?>
<?php echo $month ?>
<?php endif; ?>
</td>
<td valign='top' width='30%' class="day">
<?php if ($passed['day'] != $day): 
$passed['day'] = $day;
?>
<?php echo $day ?> (<a href="<?php echo JRoute::_( 'index.php?task=add&date='.$date ) ?>"><?php echo JText::_("Add event") ?></a>)

<?php endif; ?>
</td>
<td valign='top' width='50%' class="event">
<?php if ($rows = $this->getSharingByDate($date)) :?>
	<?php foreach ($rows as $row) : ?>
	<div class="event">
	<span class="time"><?php echo $row->time ?> - <?php echo $row->end ?></span>
	<span class="group"><?php echo $row->group ?></span>
	</div>
	<?php endforeach ; ?>

<?php endif ; ?>
</td>
</tr>
<?php endfor; ?>
</table>